Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

send files HTTP request should stream #629

Merged
merged 5 commits into from
Nov 20, 2017
Merged

send files HTTP request should stream #629

merged 5 commits into from
Nov 20, 2017

Conversation

pgte
Copy link
Contributor

@pgte pgte commented Nov 17, 2017

The HTTP multipart implementation provides a streaming interface but doesn't allow adding files mid-flight.
This PR does that and bases all the APIs that need to send files on that.
Should fix #628 (and, by association, ipfs/js-ipfs#823).

@codecov
Copy link

codecov bot commented Nov 17, 2017

Codecov Report

Merging #629 into master will decrease coverage by 0.01%.
The diff coverage is 90.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #629      +/-   ##
==========================================
- Coverage   83.86%   83.85%   -0.02%     
==========================================
  Files         112      108       -4     
  Lines        1624     1604      -20     
==========================================
- Hits         1362     1345      -17     
+ Misses        262      259       -3
Impacted Files Coverage Δ
src/files/create-add-stream.js 100% <100%> (ø)
src/index.js 88.88% <100%> (ø) ⬆️
src/utils/converter.js 71.42% <100%> (-20.24%) ⬇️
src/utils/prepare-file.js 92.3% <100%> (ø)
src/object/appendData.js 85.71% <100%> (+3.36%) ⬆️
src/util/url-add.js 82.75% <100%> (-1.62%) ⬇️
src/util/fs-add.js 77.77% <100%> (-1.17%) ⬇️
src/object/setData.js 38.09% <57.14%> (+8.68%) ⬆️
src/utils/module-config.js 60% <66.66%> (ø) ⬆️
src/utils/send-one-file.js 80% <80%> (ø)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4b8ed1...7403afc. Read the comment docs.

@ghost ghost assigned pgte Nov 17, 2017
@ghost ghost added the in progress label Nov 17, 2017
@pgte pgte changed the title WIP: send files HTTP request streams send files HTTP request should stream Nov 18, 2017
@pgte pgte requested a review from daviddias November 18, 2017 08:19
Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase master onto this branch, otherwise LGTM :)

// This does not work
// this.once('drain', () => {
// callback()
// })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do back-pressure per file item, but once inside a file we don't. So it's optimised for a lot of files, but not for large files. If that comes to be a problem, I think we should open a different issue to tackle it..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind writing this note as the comment as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to fix individual file back-pressure in this PR: 782beb9

Copy link
Contributor Author

@pgte pgte Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to limit it to Node only though, because a browser HTTP request does not stream..
7403afc

callback(null, ds)
})
}
module.exports = (send) => SendFilesStream(send, 'add')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't exist anymore, you need to rebase master onto this branch

src/files/add.js Outdated
qs.hash = opts.hash
} else if (opts.hashAlg != null) {
qs.hash = opts.hashAlg
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did all of this options went?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/files/add.js Outdated

send.andTransform(request, (response, cb) => {
converter(ProgressStream.fromStream(opts.progress, response), cb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still doing Progress reports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -6,7 +6,6 @@ const isNode = require('detect-node')
const ndjson = require('ndjson')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you are at it, wanna rename this file to send-request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. In 6f25c3f

@pgte
Copy link
Contributor Author

pgte commented Nov 20, 2017

@diasdavid rebased.

@daviddias daviddias merged commit dae62cb into master Nov 20, 2017
@daviddias daviddias deleted the fix/add-stream branch November 20, 2017 10:47
@ghost ghost removed the in progress label Nov 20, 2017
@daviddias
Copy link
Contributor

This is fantastic @pgte !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

createAddStream implementation buffers instead of streaming
2 participants